package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.model.auto.Question;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.ExamQuestionMapper;
import com.fc.test.model.auto.ExamQuestion;
import com.fc.test.model.auto.ExamQuestionExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 *  ExamQuestionService
 * @Title: ExamQuestionService.java 
 * @Package com.fc.test.service 
 * @author martins_自动生成
 * @email 610817750@qq.com
 * @date 2019-12-03 14:27:57  
 **/
@Service
public class ExamQuestionService implements BaseService<ExamQuestion, ExamQuestionExample>{
	@Autowired
	private ExamQuestionMapper examQuestionMapper;
	
      	   	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ExamQuestion> list(Tablepar tablepar,String name){
	        ExamQuestionExample testExample=new ExamQuestionExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andPaperIdLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ExamQuestion> list= examQuestionMapper.selectByExample(testExample);
	        PageInfo<ExamQuestion> pageInfo = new PageInfo<ExamQuestion>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			ExamQuestionExample example=new ExamQuestionExample();
			example.createCriteria().andIdIn(lista);
			return examQuestionMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ExamQuestion selectByPrimaryKey(String id) {
				
			return examQuestionMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ExamQuestion record) {
		return examQuestionMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ExamQuestion record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return examQuestionMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(ExamQuestion record, ExamQuestionExample example) {
		
		return examQuestionMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ExamQuestion record, ExamQuestionExample example) {
		
		return examQuestionMapper.updateByExample(record, example);
	}

	@Override
	public List<ExamQuestion> selectByExample(ExamQuestionExample example) {
		
		return examQuestionMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ExamQuestionExample example) {
		
		return examQuestionMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ExamQuestionExample example) {
		
		return examQuestionMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param examQuestion
	 * @return
	 */
	public int checkNameUnique(ExamQuestion examQuestion){
		ExamQuestionExample example=new ExamQuestionExample();
		example.createCriteria().andPaperIdEqualTo(examQuestion.getPaperId());
		List<ExamQuestion> list=examQuestionMapper.selectByExample(example);
		return list.size();
	}


	public List<Question> listBypaperId(String id) {
		return examQuestionMapper.listBypaperId(id);

	}
}
